package com.wanli.agent.homepage;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wanli.agent.R;
import com.wanli.agent.base.BaseActivity;
import com.wanli.agent.base.DataCallBack;
import com.wanli.agent.bean.AgentRankListBean;
import com.wanli.agent.bean.AgentShowBean;
import com.wanli.agent.homepage.adapter.LookRankListAdapter;
import com.wanli.agent.homepage.model.HomePageModelImpl;
import com.wanli.agent.homepage.model.IHomePageModel;
import com.wanli.agent.widget.AppTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LookRankActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private String agent_id;
    private String type;
    private IHomePageModel homePageModel = new HomePageModelImpl();
    private LookRankListAdapter listAdapter;
    private List<AgentShowBean.DataBean> beanList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_look_rank);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        agent_id = getIntent().getStringExtra("agent_id");
        type = getIntent().getStringExtra("type");
        beanList = new ArrayList<>();
        listAdapter = new LookRankListAdapter(beanList);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        recyclerView.setAdapter(listAdapter);
        if ("parents".equals(type)) {
            titleBar.setTitle("上级服务商");
            requestAgentGetParents();
        } else {
            titleBar.setTitle("下级服务商");
            requestAgentGetChilds();
        }
    }

    public void requestAgentGetParents() {
        homePageModel.requestAgentGetParents(agent_id, new DataCallBack<AgentRankListBean>() {
            @Override
            public void onSuccessful(AgentRankListBean bean) {
                beanList.clear();
                beanList.addAll(bean.getData());
                listAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }

    public void requestAgentGetChilds() {
        homePageModel.requestAgentGetChilds(agent_id, new DataCallBack<AgentRankListBean>() {
            @Override
            public void onSuccessful(AgentRankListBean bean) {
                beanList.clear();
                beanList.addAll(bean.getData());
                listAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }
}
